import {defineStore} from "pinia";
import http from '../utils/http'
let system_title = localStorage.getItem("system_title")? localStorage.getItem("system_title"): import.meta.env.VITE_APP_NAME
const locale = localStorage.getItem("lang") || "zhCN"
export const adminStore = defineStore('AdminStore',{
    state() {
       return {
          phoneList: [], // 手机列表
          lookNum: 0, // 访问次数
          linkDevice: 0, // 连接的设备数量
          system_title,
          isOpenDrawer: false,
          lang: locale,
          isChannelEditorOpen: false, // 新增：控制通道名称编辑器抽屉的状态
       }
    },
    actions: {
      async initPhoneList() {
         let res = await http.adminInstance.get("/user/getAllUserList")
         this.phoneList = res.data.data
      },
      // 新增：打开或关闭通道名称编辑器
      toggleChannelEditor(isOpen: boolean) {
        this.isChannelEditorOpen = isOpen;
      }
    },
    getters: {
      // 是否能够发送短信给用户
      isAableSendMsg(state) {
         // @ts-ignore
         return (state.phoneList.length > 0 && state.phoneList.some(item => item.isWatch))
      },
       // 能够发送短信的数量
       AableSendMsgNum(state) {
         return state.phoneList.filter((item:any) => item.isWatch).length
      }
    }
})
